<?php
class ClassAction extends CommonAction {

 public function classList(){

        import("ORG.Util.Page");

        $Form = M('class_base_info');
        $count = $Form->count();
        $Page = new Page ($count , 15 );
        $show = $Page->show();
        $classInfo = $Form->limit( $Page->firstRow . ',' . $Page->listRows )->select();

        $this->assign( 'page' , $show );
        $this->assign( 'classInfo' , $classInfo );
        $this->display("classlist");
    }

    public function classDel(){

        $class_code = $_GET['class_code'];
        $M = M('class_base_info');
        $M->where("class_code=$class_code")->delete();

        $classInfo = $M->select();
        $this->assign( 'classInfo' , $classInfo );
        $this->display("classlist");
    }

    public function classAdd(){

        $className = $_POST['class_name'];
        $class_code = $_POST['class_code'];

        $M = M('class_base_info');

        if( !empty($className) &&  empty($class_code) ){
            $Form = D("class_base_info");
            if ( $Form->create() ) {
                if ( false !== $Form->add() ) {
                    $this->assign("jumpUrl","classList");
                    $this->success('数据添加成功！');
                } else {
                    $this->assign("jumpUrl","classList");
                    $this->error('数据写入错误');
                }
            }
            exit;
        }elseif( !empty($class_code) ){
            if ($vo = $M->create()) {
                $data['class_code'] = $class_code;
                $data['class_name'] = $_POST['class_name'];
                $data['class_up_code'] = $_POST['class_up_code'];
                $list = $M->save($data);
            }
            if ($list !== false) {
                $this->assign("jumpUrl","classList");
                $this->success('数据更新成功！');
            } else {
                $this->assign("jumpUrl","classList");
                $this->error("没有更新任何数据!");
            }
            exit;
        }
        $editCode = $_GET['class_code'];
        $editInfo = $M->where("class_code=$editCode")->select();
        $classInfo = $M->where()->select();
        $this->assign('editCode' , $editCode);
        $this->assign('editInfo' , $editInfo);

        $classInfo = $M->select();
        $this->assign('classInfo' , $classInfo);
        $this->display("classadd");
    }
}
?>